/** 
 * IconButtonUI.java
 * @author Lex
 * 2007-9-7 ����07:04:55
 */
package lex.title;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicButtonUI;
import lex.util.ButtonState;

public class WindowButtonUI extends BasicButtonUI {
	private Image normal = null;
	private Image rollover = null;
	private Image pressed = null;
	private Image disabled = null;

	public WindowButtonUI(Image normal, Image rollover) {
		this(normal, rollover, normal, normal);
	}

	public WindowButtonUI(Image normal, Image rollover, Image pressed, Image disabled) {
		super();
		this.normal = normal;
		this.rollover = rollover;
		this.pressed = pressed;
		this.disabled = disabled;
	}

	public Dimension getMinimumSize(JComponent c) {
		return this.getPreferredSize(c);
	}

	public Dimension getPreferredSize(JComponent c) {
		Image img = this.getImage((JButton) c);
		return new Dimension(img.getWidth(null), img.getHeight(null));
	}

	public void paint(Graphics g, JComponent c) {
		g.drawImage(getImage((JButton) c), 0, 0, null);
	}

	private Image getImage(JButton b) {
		int status = ButtonState.getState(b);
		switch (status) {
		case ButtonState.rollover:
			return rollover;
		case ButtonState.pressed:
			return pressed;
		case ButtonState.disabled:
			return disabled;
		case ButtonState.normal:
		default:
			return normal;
		}
	}
}
